package com.example.zz.example.datastructures;

import java.util.Stack;

/**
 * Created by zhangzhuo.
 * Blog: https://blog.csdn.net/zhangzhuo1024
 * Date: 2020/5/3
 *
 * Stack基础方法：
 * push：添加
 * pop：删除
 * peek：获取栈顶元素
 */
public class StackDemo {

    public static void main(String[] args) {


        Stack<Integer> integers = new Stack<>();
        integers.push(1);
        integers.push(2);
        for (Integer integer : integers) {
            System.out.println(integer);
        }

        push(1);
        push(2);
        push(3);
        int pop = pop();
        int pop1 = pop();
        push(4);
        int pop2 = pop();
        push(5);
        int pop3 = pop();
        int pop4 = pop();
        System.out.println(" 1 = " + pop + "  2 = " + pop1 + "  3 = " + pop2 + "  4 = " + pop3 + "  5 = " + pop4);


    }

    static Stack<Integer> stack1 = new Stack<Integer>();
    static Stack<Integer> stack2 = new Stack<Integer>();

    public static void push(int node) {
        stack1.add(node);
        System.out.println(node);
    }

    public static int pop() {
        if (stack2.size() <= 0) {

            int size = stack1.size();
            System.out.println("stack1.size() " + size);
            for (int i = 0; i < size; i++) {
                System.out.println("i  " + i);
                Integer pop = stack1.pop();
                System.out.println("push  " + pop);
                stack2.push(pop);
                String aa = Integer.toBinaryString(2);
                String[] split = aa.split("");
            }
        }

        return stack2.pop();
    }

}
